package dao;

import Service.UserService;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import pojo.User;

import static org.junit.Assert.*;

public class HelloSpring {


    @Test
    public void print() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        //通过Printer bean的id来获取Printer实例
        Printer printer = (Printer) context.getBean("Printer");
        String content = "千方百计"
                +"魏晨"
                +"时间"
                +"3：14"
                +"专辑"
                +"千方百计"
                +"播放量"
                +"100w";
        printer.print(content);
    }

    @Test
    public void getHello() {
        //通过ClassPathXmlApplicationContext实例化Spring的上下文
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        //通过ApplicationContext的getBean()方法，根据id来获取bean的实例
        HelloSpring helloSpring = (HelloSpring) context.getBean("HelloSpring");
        //执行pring（）方法
        helloSpring.print();
    }

    @Test
    public void setHello() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService service = (UserService) ctx.getBean("userService");

        User user = new User();
        user.setId(1);
        user.setUsername("test");
        user.setPassword("123456");
        user.setEmail("test@xxx.com");
        service.sava(user);
    }
}
